#include <stdio.h>
#include <string.h>
#include <iostream>

int main()
{
    FILE *fp = fopen("meminfo", "r");
    if (fp == nullptr) {
        std::cout << "fopen return " << errno << std::endl;
        return 0;
    }

    constexpr int keyLength = 32;
    char key[keyLength];
    int cmaFree = 0;
    while (fscanf(fp, "%s%d%*s", key, &cmaFree) > 0) {
        std::cout << key << ": " << cmaFree << " kB" << std::endl;
        if (strcmp(key, "CmaFree:") == 0) {
            return cmaFree;
        }
    }

    fclose(fp);
    return 0;
}
